﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace aerowan.common
{
    public class Utility
    {
        public static string PasswordHash(string password)
        {
            SHA1 sha = SHA1.Create();
            byte[] res = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
            sha.Dispose();
            return ToHexString(res);
        }
        public static string ToHexString(byte[] data)
        {
            string result = "";
            foreach (byte b in data)
            {
                result += string.Format("{0:X2}", b);
            }
            return result;
        }
        public static string CreateRandomPassword(int passwordLength)
        {
            string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
            char[] chars = new char[passwordLength];
            Random rd = new Random();

            for (int i = 0; i < passwordLength; i++)
            {
                chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
            }

            return new string(chars);
        }
        public static double LatitudeFsToDeg(long fs)
        {
            double val = (double)fs;
            return Math.Round(val * (90.0D / (10001750.0D * 65536.0D * 65536.0D)), 4);
        }
        public static double LongitudeFsToDef(long fs)
        {
            double val = (double)fs;
            return Math.Round(val * (360.0D / (65536.0D * 65536.0D * 65536.0D * 65536.0D)), 4);
        }
    }
}
